﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using Circa.Protocol.Irc;

namespace Circa {

    /// <summary>
    /// Interaction logic for ConsolePage.xaml
    /// </summary>
    public partial class ConsolePage: Page {

        public App App { get { return (App) Application.Current; } }
        public ContainerWindow ContainerWindow { get; private set; }

        private ConsolePage( ) { }

        public ConsolePage( ContainerWindow container ) {
            InitializeComponent( );
            ContainerWindow = container;
        }

        private void page_Loaded( object sender, RoutedEventArgs e ) {
            e.Handled = true;

            Span s;
            s = new Span( );
            s.Inlines.Add( new Run("Circa: It's ") );
            s.Inlines.Add( new Italic( new Run( "Still" ) ) );
            s.Inlines.Add( new Run(" Not Lame!") );
            flowDoc.Blocks.Add( new Paragraph( s ) );

            s = new Span( );
            s.Inlines.Add( new Run( "Connecting to auto-connect networks..." ) );
            flowDoc.Blocks.Add( new Paragraph( s ) );

            foreach ( Network n in App.Networks ) {
                n.NewServerConnection += new EventHandler<NewServerConnectionEventArgs>( network_NewServerConnection );
                if ( n.AutoConnect ) {
                    n.Connect( );
                }
            }

            inputTextBox.Focus( );
        }

        private void network_NewServerConnection( object sender, NewServerConnectionEventArgs e ) {
            Network n = (Network) sender;
            ServerPage sp = new ServerPage( ContainerWindow, e.Server );
            ContainerWindow.AddPage( e.Server.Name, sp );
        }

    }

}
